#include "./mqtt_conn.h"


namespace server {

void MqttConn::connect(const MqttInfo& info) {

    m_client = std::make_unique<mqtt::client>(
        info.url,
        info.client_id
    );
    
    auto opt = mqtt::connect_options_builder(MQTTVERSION_3_1_1)    
        .keep_alive_interval( std::chrono::seconds(10) )
        .clean_session()
        .user_name(mqtt::string_ref(info.username))
        .password(mqtt::binary_ref(info.password))
        .automatic_reconnect( std::chrono::milliseconds(5), std::chrono::milliseconds(10) )
        .connect_timeout( std::chrono::milliseconds(10) )
        .finalize();
    m_client->connect(opt);
}

}

